home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / amc / amc_install.exe / {app} / Scripts / darktown (FR).ifs < prev    next >
Encoding:
Text File  |  2005-03-13  |  8.1 KB  |  288 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Doomer
  8. Title=Darktown.com
  9. Description=Darktown.com (module de recherche toute catΘgories)
  10. Site=http://www.darktown.com
  11. Language=FR
  12. Version=2004-06-10
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program DARKTOWN_SEARCH;
  23.  
  24. //ParamΦtres du script
  25. const
  26.  
  27.   TempsPause = 1500;      // 1000 = 1 Seconde (permet d'Θviter les timeout en cas de saturation serveur)
  28.   UrlStart = 'http://www.darktown.com/view.php?uid=';
  29.   UrlEnd = '"';
  30.  
  31.  
  32.  
  33. var
  34.   MovieName: string;
  35.   Page: TStringList;
  36.   Categorie : string;
  37.  
  38. {*
  39. Remplace le codage HTML par les caractΦres bizarres de la langue Allemande
  40. *}
  41. function HTMLReplace(Title: string): string;
  42. var
  43.   i: Integer;
  44. begin
  45.         Title := StringReplace(Title,'%20',' ');
  46.         Title := StringReplace(Title,'%26','&');
  47.         Title := StringReplace(Title,'%2F','/');
  48.         Title := StringReplace(Title,'%FC','ⁿ');
  49.         Title := StringReplace(Title,'%F6','÷');
  50.         Title := StringReplace(Title,'%22','"');
  51.         Title := StringReplace(Title,'%E4','Σ');
  52.         Title := StringReplace(Title,'%2C',',');
  53.         Title := StringReplace(Title,'%21','!');
  54.         Title := StringReplace(Title,'%2B','+');
  55.         Title := StringReplace(Title,'%B4','''');
  56.         Title := StringReplace(Title,'%D6','╓');
  57.         Title := StringReplace(Title,'%DF','▀');
  58.         Title := StringReplace(Title,'%C4','─');
  59.  
  60.         result := Title;
  61. end;
  62.  
  63. {*
  64. Cherche un ligne dans un tableau TStringList et retourne son indice
  65. *}
  66. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  67. var
  68.   i: Integer;
  69. begin
  70.   result := -1;
  71.   if StartAt < 0 then
  72.     StartAt := 0;
  73.   for i := StartAt to List.Count-1 do
  74.     if Pos(Pattern, List.GetString(i)) <> 0 then
  75.     begin
  76.       result := i;
  77.       Break;
  78.     end;
  79. end;
  80.  
  81. {*
  82. Compte les pages HTML α balayer pour lister toutes les rΘponses
  83. *}
  84. function PageCounter(address: string): Integer;
  85. var
  86. counter: Integer;
  87. BeginPos: Integer;
  88. EndPos: Integer;
  89.  
  90. begin
  91.   Page := TStringList.Create;
  92.   Page.Text := GetPage(Address);
  93.   Address := GetPage(Address);
  94.   BeginPos := Pos('/search.php?',Address);
  95.   delete(Address,1,BeginPos-1);
  96.   EndPos := Pos('"',Address);
  97.   Page.SetString(0,Copy(Address,1,EndPos-1));
  98.   delete(Address,1,9);
  99.   if (BeginPos > 0) then
  100.   begin
  101.     repeat
  102.       begin
  103.         counter := counter + 1;
  104.         BeginPos := Pos('/search.php?',Address);
  105.         Delete(Address,1,BeginPos-1);
  106.         EndPos := Pos('"',Address);
  107.         Page.SetString(counter,Copy(Address,1,EndPos-1));
  108.         delete(Address,1,9);
  109.       end;
  110.     until(BeginPos <= 0);
  111.   end
  112.     counter := (counter div 2);
  113.     result := counter;
  114. end;
  115.  
  116. {*
  117. m'a servi jadis au dΘbogage
  118. *}
  119. procedure testcounter(compteur: Integer);
  120. var
  121. i: Integer;
  122. begin
  123.   for i:=0 to compteur-1 do
  124.   ShowMessage(IntToStr(compteur) + Page.GetString(i));
  125. end;
  126.  
  127. {*
  128. Analyse le code HTML de la page pour remplir le PickTree
  129. *}
  130. procedure AnalyzePage(Address: string);
  131. var
  132.   LineNr: Integer;
  133.   BeginPos: Integer;
  134.   EndPos: Integer;
  135.   Element1: string;
  136.   Element2: string;
  137.   Element3: string;
  138.   Element4: string;
  139.   Title: string;
  140.   TitleAddr: string;
  141.   i: Integer;
  142.   BeginType: Integer;
  143.   BeginCat: Integer;
  144.   BeginName: Integer;
  145.   EndName: Integer;
  146.   stype: string;
  147.   sname: string;
  148.  
  149. begin
  150.   Sleep(TempsPause); // Attente X seconde : Evite les timeout sur le serveur
  151.   Element1 := 'href="';
  152.   Element2 := 'http://www.amazon.de/exec/obidos/external-search?tag=darktown0d-21&keyword=';
  153.   Element3 := 'index';
  154.   Element4 := '">';
  155.   LineNr := PageCounter(Address);
  156. //  testcounter(LineNr);
  157.   Address := GetPage(Address);
  158.   BeginPos := Pos(UrlStart,Address);
  159.   if BeginPos > 0 then
  160.   begin
  161.   PickTreeClear;
  162.  for i:=0 to LineNr do
  163.   begin
  164.   repeat
  165.     begin
  166.          delete(Address,1,BeginPos-1);
  167.         EndPos := Pos(UrlEnd,Address);
  168.         TitleAddr := Copy(Address,1,EndPos-1);
  169.          BeginName := Pos(Element1 + Element2,Address) + length(Element1 + Element2) - 1;
  170.          EndName := Pos('index=',Address);
  171.          sname := Copy(Address,BeginName+1,EndName-BeginName-2);
  172.          BeginType := Pos('type=',Address);
  173.          BeginCat := Pos('category=', Address);
  174.          stype := Copy(Address,Begintype+5,BeginCat-BeginType-6);
  175.         Title := sname + ' - ' + stype;
  176.         HTMLDecode(Title);
  177.         Title := HTMLReplace(Title);
  178.         delete(Address,1,length(UrlStart));
  179.         EndPos := Pos(Element4,Address);
  180.         PickTreeAdd(Title,TitleAddr);
  181.         BeginPos := Pos(UrlStart,Address);
  182.     end;
  183.   until (BeginPos <= 0);
  184.   if Pos('<html>', Page.GetString(i)) <=0 then
  185.      Address := GetPage(Page.GetString(i));
  186.   end
  187. if PickTreeExec(Address) then
  188. begin
  189.   Address := GetPage(Address);
  190.   BeginPos := Pos('<img src="http://img.darktown.com',Address);
  191.   delete(Address,1,BeginPos + 9);
  192.   EndPos := Pos('"',Address);
  193.   TitleAddr := Copy(Address,1,EndPos-1);
  194.   GetPicture(TitleAddr);
  195. end
  196. end;
  197. Page.Free;
  198. end;
  199.  
  200. {*
  201. retourne la catΘgorie de recherche pour le site Darktown
  202. *}
  203. function WhatCategorie(): string;
  204. var
  205. thecat : string;
  206. begin
  207.     PickTreeClear;
  208.     PickTreeAdd('Logiciels','anwender'); // ligne sΘlectionnΘe par dΘfaut
  209.     PickTreeAdd('Jeux','spiele');
  210.     PickTreeAdd('Audio','audio');
  211.     PickTreeAdd('PSX','psx');
  212.     PickTreeAdd('PS2','psx2');
  213.     PickTreeAdd('Dreamcast','dreamcast');
  214.     PickTreeAdd('XBox','xbox');
  215.     PickTreeAdd('GameCube','gamecube');
  216.     PickTreeAdd('DVD','dvd');
  217.     PickTreeAdd('VCD','vcd');
  218.     PickTreeAdd('VHS','vhs');
  219.     if PickTreeExec(thecat) then
  220.     begin
  221.       result := thecat
  222.     end
  223. end;
  224.  
  225. {*
  226. ne sert plus α rien, elle servait juste α remplir le champs pattern de la requΩte php
  227. *}
  228. function FindPage():string;
  229. var
  230.    CharCode : string;
  231. begin
  232.           CharCode := copy(MovieName,1,1);
  233.           case AnsiUpperCase(CharCode) of
  234.             'A': CharCode := 'A';
  235.             'B': CharCode := 'B';
  236.             'C': CharCode := 'C';
  237.             'D': CharCode := 'D';
  238.             'E': CharCode := 'E';
  239.             'F': CharCode := 'F';
  240.             'G': CharCode := 'G';
  241.             'H': CharCode := 'H';
  242.             'I': CharCode := 'I';
  243.             'J': CharCode := 'J';
  244.             'K': CharCode := 'K';
  245.             'L': CharCode := 'L';
  246.             'M': CharCode := 'M';
  247.             'N': CharCode := 'N';
  248.             'O': CharCode := 'O';
  249.             'P': CharCode := 'P';
  250.             'Q': CharCode := 'Q';
  251.             'R': CharCode := 'R';
  252.             'S': CharCode := 'S';
  253.             'T': CharCode := 'T';
  254.             'U': CharCode := 'U';
  255.             'V': CharCode := 'V';
  256.             'W': CharCode := 'W';
  257.             'X': CharCode := 'X';
  258.             'Y': CharCode := 'Y';
  259.             'Z': CharCode := 'Z';
  260.        else CharCode := '0-9';
  261.           end;
  262.       result := CharCode;
  263. end;
  264.  
  265. begin
  266.   if CheckVersion(3,5,0) then
  267.   begin
  268.     MovieName := GetField(fieldTranslatedTitle);
  269.     if MovieName = '' then
  270.       MovieName := GetField(fieldOriginalTitle);
  271.  
  272.     begin
  273.      if Input('Darktown.com Import', 'ElΘment de recherche :', MovieName) then
  274.       begin
  275.        // dans la requΩte de recherche les espaces sont remplacΘs par des +
  276.        MovieName := StringReplace(MovieName,' ','+');
  277.        // l'utilisateur doit sΘlectionner une catΘgorie de recherche
  278.        Categorie := WhatCategorie();
  279.        // on analyse le code des pages HTML pour remplir le PickTree
  280.        AnalyzePage('http://www.darktown.com/search.php?action=search&what=' + MovieName + '&&category='+Categorie+'&&submit=++SUCHE++');
  281.        // on affiche le rΘsultat
  282.        //DisplayResults;
  283.       end;
  284.     end
  285.   end else
  286.    ShowMessage('Ce script requiert une version plus rΘcente de Ant Movie Catalog (au moins la version 3.5.0)');
  287. end.
  288.